import axios from './axios'
import qs from 'qs'
import {baseUrl} from '@/config/config'

/**
 * 获取网吧列表
 * @param {pageSize, pageIndex, keyword} params
 */
export const getCybercafes = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/cybercafes?' + qs.stringify(params),
            method: 'get'
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}
/**
 * 网吧信息详情
 * @param {id} params
 */
export const getCybercafesDetail = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/cybercafes/' + params,
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 网吧信息详情编辑
 * @param {id} param
 * @data {name,address,contacts,tel,email,ownDNS,thirdDNS} data
 */
export const editCybercafesDetail = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/cybercafes/' + params.id,
            method: 'put',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            data: JSON.stringify(params)
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 网吧信息详情新增
 * @param {name,address,contacts,tel,email,ownDNS,thirdDNS} params
 */
export const addCybercafesDetail = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/cybercafes',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            method: 'post',
            data: JSON.stringify(params)
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 网吧信息详情删除
 * @param {id} params
 */
export const deleteCybercafesDetail = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/cybercafes/' + params,
            method: 'delete'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 网吧数量
 */
export const countCybercafe = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/count/cybercafe',
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 故障分析
 * @param {way,ip} params
 */
export const faultAnalysis = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/fault/analysis?' + qs.stringify(params),
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 在线情况历史记录
 * @param {way,ip} params
 */
export const onlineHistoricRecords = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/online/historicrecords?' + qs.stringify(params),
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * ping历史记录
 * @param {pageSize,lastId,barId} params
 */
export const pingHistoricRecords = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/ping/historicrecords?' + qs.stringify(params),
            // url: 'http://192.168.10.232:8080/api/ping/historicrecords?' + qs.stringify(params),
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 获取省市信息
 * @param {} params 
 */
export const getCitys = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            // url: baseUrl + '/api/ping/historicrecords?' + qs.stringify(params),
            url: baseUrl + '/api/area/code',
            method: 'get'
        }).then(res => {
            // console.log(res)
            resolve(res.data)
        })
    })
}
/**
 * ping历史记录
 * @param {} params
 */
export const templateFileDownload = () => {
  return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/api/file/templatefile/download',
          method: 'get',
          responseType: 'blob'
      }).then(res => {
          resolve(res.data)
      })
  })
}
/**
 * 获取路由列表
 * @param {pageSize, pageIndex, barId} params
 */
export const tracerouteResults = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/traceroute/results?' + qs.stringify(params),
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 删除路由列表
 * @param {pageSize, pageIndex, barId} params
 */
export const deleteTracerouteResults = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/traceroute/results/' + params,
            method: 'delete'
        }).then(res => {
            resolve(res.data)
        })
    })
}
/**
 * 预览路由
 * @param {id} params
 */
export const previewTracerouteResults = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/traceroute/results/' + params,
            method: 'get'
        }).then(res => {
            resolve(res.data)
        })
    })
}
